# Server program

from socket import *

# Set the socket parameters
host = "localhost"
port = 21567
buf = 1024
addr = (host,port)

userlist = []
userListString = ""
# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)

# Receive messages
while 1:
    data,addr = UDPSock.recvfrom(buf)
    if not data:
        print "Client has exited!"
        break
    else:
        print "\nReceived message '", data,"'"
        if addr not in userlist:
            userlist.append(addr)
            userListString = userListString + "," + str(addr[1])
            UDPSock.sendto(userListString, addr)
            print userlist
        print userlist
# Close socket
UDPSock.close()
